/**
 * 用户相关model
 */

const db = require('../platform').db;
// const md5 = require('md5');

const getUserById = async (id) => {
  const userInfo = await db.user.findOne({
    where: {
      id: id,
      status: 1,
    }
  });
  return userInfo;
}

const getUserByNameAndPass = async (username, password) => {
  const user = await db.user.findOne({
    where: {
      user_name: username,
      password: password,
      status: 1,
    }
  });
  if (user !== null) {
    return user; 
  } else {
    throw new Error('找不到该用户');
  }
}

module.exports = {
  getUserById,
  getUserByNameAndPass,
}